package response;

import protocol.CtfActionException;
import utils.Conversions;

/**
 * Represents the server response to a PICKUP message type (3). 
 * 		Object ID
 * 			 0	Error, nothing at this cell to pick up
 * 			 1	Flag
 * 			 2	Bombs
 */
public class PickupBody {
	public static final int LENGTH = 2;
	
	/* Field set */
	int objectId;
	
	public int getObjectId() { return objectId; }
	
	/**
	 * Parses the received byte array. (Client usage)
	 * @param response
	 * @throws CtfActionException
	 */
	public PickupBody( byte[] response ) throws CtfActionException {
		objectId = Conversions.bytesToInt(response);
		if ( objectId == -1 )
			throw new CtfActionException("3:pickup");
	}
	
	/**
	 * Set objectId field. (Server usage)
	 * @param objectId
	 */
	public PickupBody( int objectId ) {
		this.objectId = objectId;
	}
	
	/**
	 * Converts the PickupBody to a byte array in network byte order.
	 * (Server usage)
	 * @return byte array
	 */
	public byte[] toNetworkByteArray() {
		return Conversions.intToBytes(objectId);
	}
}
